home *** CD-ROM | disk | FTP | other *** search
- Path: castle.nando.net!news
- From: actuary@nando.net (Bill McCarthy)
- Newsgroups: comp.lang.c
- Subject: Re: more problems with qsort
- Date: 2 Mar 1996 02:31:41 GMT
- Organization: Nando.net Public Access
- Message-ID: <4h8bud$1vd@castle.nando.net>
- References: <177399702S86.JW1675A@american.edu> <4h0j9e$ng5@clarknet.clark.net>
- Reply-To: actuary@nando.net (Bill McCarthy)
- NNTP-Posting-Host: vyger117.nando.net
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <4h0j9e$ng5@clarknet.clark.net>,
- yom@clark.net (yom) writes:
-
- >Since you're trying to sort a char**, the qsort function call must
- >look like this:
- >
- >qsort(array,lines,sizeof(char **),(int (*)(void *,void *)) compare);
- >
- >And your compare function must be defined like this:
- >
- >int compare(char **a,char **b) {return strcmp(*a,*b);}
-
- Didn't you mean to type "sizeof( char * )" which, IMHO, could be
- better expressed as "sizeof array[0]" ? Also, there's no need to
- further complicate the call of qsort with the cast on compare if
- you define compare() as:
-
- int compare( const void *a, const void *b )
- {
- return strcmp( *(const char **)a, *(const char **)b );
- }
-
- Bill McCarthy
- actuary@nando.net
- Wendell, NC USA
-